package com.michael.demos.ddd.springboot.usecases;

import com.michael.demos.ddd.springboot.domains.Account;
import com.michael.demos.ddd.springboot.domains.Money;
import com.michael.demos.ddd.springboot.ports.in.GetAccountBalanceQuery;
import com.michael.demos.ddd.springboot.ports.out.LoadAccountPort;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;

@RequiredArgsConstructor
class GetAccountBalanceService implements GetAccountBalanceQuery {

    private final LoadAccountPort loadAccountPort;

    @Override
    public Money getAccountBalance(Account.AccountId accountId) {
        return loadAccountPort.loadAccount(accountId, LocalDateTime.now())
                              .calculateBalance();
    }
}
